package com.gudaomai.ekproject.service.impl;

import com.gudaomai.ekproject.common.CommonConstant;
import com.gudaomai.ekproject.common.CommonException;
import com.gudaomai.ekproject.common.MsgConstant;
import com.gudaomai.ekproject.entity.Element;
import com.gudaomai.ekproject.mapper.ElementMapper;
import com.gudaomai.ekproject.service.IElementService;
import com.gudaomai.ekproject.service.IPageService;
import com.gudaomai.ekproject.service.impl.BaseServiceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 画面项目 服务实现类
 * </p>
 *
 * @author zengHuaLu
 * @since 2017-06-26
 */
@Service
public class ElementServiceImpl extends BaseServiceImpl<ElementMapper, Element> implements IElementService {

	@Autowired
	IElementService elementServ;
	@Autowired
	protected MessageSource messageSource;
	@Autowired
	ElementMapper elementMapper;
	@Autowired
	IPageService pageServ;

	// 一对多关系，根据page_id获取Element
	@Override
	public List<Element> getElementByPageId(String pageId) throws CommonException {

		List<Element> elements = elementMapper.getElementsByPageId(pageId);

		if (null != pageServ.selectById(pageId) && elements.size() > 0) {
			// 查询到对应记录，将记录集合返回
			return elements;
		} else {
			// 查询不到记录，抛出异常
			throw new CommonException(CommonConstant.RESULT_CODE_NOT_FOUND,
					getMessage(MsgConstant.RET_ELEMENT_SELECT_NOTEXIST));
		}
	}
}
